{include file="public/header" /}
<body>
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-tab-content">
            <form id="roleFormData" class="layui-form layui-form-pane" autocomplete="off">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-required">名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" id="roleName" lay-verify="name" placeholder="请输入名称" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked="" name="status" lay-text="启用|禁用" lay-skin="switch">
                    </div>
                </div>

                <div class="btn-block">
                    <button type="button" onclick="sendRoleFormData()" class="layui-btn layui-btn-normal"><i class="fa fa-check"></i>提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary"><i class="fa fa-refresh"></i>重置</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script>
    layui.use('form',function () {
        var form = layui.form;

    });

    function sendRoleFormData() {
        let name = $('#roleName').val()
        if (emptyCheck(name)){
            hintMsg('名称不能为空','roleName')
            return false
        }
        //弹出遮罩层，防止多次点击
        var roleAddLoad = layer.load(1,{shade:[0.5,'#FFF'],time:0})
        ajaxRequest("{:url('role/add')}",$("#roleFormData").serialize(),function (res) {
            if (res.code == 'suc'){
                sucMsg(res.msg,function () {
                    //刷新父级页面
                    xadmin.father_reload()
                    //关闭遮罩层
                    layer.close(roleAddLoad)
                    //关闭当前弹出层
                    xadmin.close()
                })
            } else {
                errMsg(res.msg,function () {
                    //关闭遮罩层
                    layer.close(roleAddLoad)
                })
            }
        })
    }
</script>
</html>